using CodePlex.TfsLibrary.ObjectModel;
using CodePlex.TfsLibrary.RepositoryWebSvc;
using CodePlex.UnitTestUtility;
using Xunit;

namespace CodePlex.CodePlexClientLibrary.Presenters
{
    public class ListViewPresenterTest
    {
        [Fact]
        public void CallsEngine()
        {
            TestableListViewPresenter presenter = TestableListViewPresenter.Create();

            presenter.Run("http://tfsUrl", "$/Foo", true, VersionSpec.Latest);

            Assert.Equal("http://tfsUrl", presenter.TfsEngine.List_TfsUrl);
            Assert.Equal("$/Foo", presenter.TfsEngine.List_ServerPath);
            Assert.Equal<VersionSpec>(VersionSpec.Latest, presenter.TfsEngine.List_Version);
            Assert.True(presenter.TfsEngine.List_Recursive);
        }

        [Fact]
        public void CallsViewDuringCallback()
        {
            TestableListViewPresenter presenter = TestableListViewPresenter.Create();

            presenter.Run("http://tfsUrl", "$/Foo", true, VersionSpec.Latest);

            Assert.NotNull(presenter.View.DisplayItem_Item);
            Assert.Equal(SourceItemResult.S_Ok, presenter.View.DisplayItem_Result);
        }

        class TestableListViewPresenter : ListViewPresenter
        {
            public readonly StubTfsEngine TfsEngine;
            public readonly StubListView View;

            TestableListViewPresenter(StubListView view,
                                      StubTfsEngine engine)
                : base(view, engine)
            {
                View = view;
                TfsEngine = engine;
            }

            public static TestableListViewPresenter Create()
            {
                return new TestableListViewPresenter(new StubListView(), new StubTfsEngine());
            }
        }
    }
}